struct Interval
{
	int start;
	int end;
	Interval() : start(0), end(0) {}
	Interval(int s, int e) : start(s), end(e) {}
};

#include <set>
#include <climits>
#include <vector>

class SummaryRanges
{
public:
	/** Initialize your data structure here. */
	std::set<int> m_set;
	SummaryRanges()
	{

	}

	void addNum(int val)
	{
		m_set.insert(val);
	}

	std::vector<Interval> getIntervals()
	{
		std::vector<Interval> result;
		auto begin = std::numeric_limits<int>::min();
		auto end = begin;
		for (auto val : m_set) {
			if (val != end + 1) {
				if (begin != std::numeric_limits<int>::min())
					result.emplace_back(begin, end);
				begin = val;
				end = val;
			} else {
				end = val;
			}
		}
		if (begin != std::numeric_limits<int>::min())
			result.emplace_back(begin, end);
		return result;
	}
};